<template>
  <div class="user-detail-container">
    <h2>用户详情</h2>
    <div class="user-card">
      <!-- 头像展示 -->
      <div class="avatar-section">
        <img :src="`/api/`+user.userinfo.imagepath" alt="用户头像" class="avatar" v-if="user.userinfo.imagepath">
        <div class="no-avatar" v-else>
          暂无头像
        </div>
      </div>

      <!-- 用户信息展示 -->
      <div class="info-section">
        <el-form :model="user" label-position="right" label-width="100px">
          <el-form-item label="用户名">
            <span class="info-text">{{ user.uname }}</span>
          </el-form-item>

          <el-form-item label="昵称">
            <span class="info-text">{{ user.userinfo.nickname || '未设置' }}</span>
          </el-form-item>

          <el-form-item label="真实姓名">
            <span class="info-text">{{ user.userinfo.realname || '未设置' }}</span>
          </el-form-item>

          <el-form-item label="年龄">
            <span class="info-text">{{ user.userinfo.age || '未设置' }}</span>
          </el-form-item>

          <el-form-item label="性别">
            <span class="info-text">{{
                user.userinfo.gender ? (user.userinfo.gender === 'male' ? '男' : '女') : '未设置'
              }}</span>
          </el-form-item>

          <el-form-item label="个性签名">
            <span class="info-text">{{ user.userinfo.signature || '暂无签名' }}</span>
          </el-form-item>

          <el-form-item label="地区">
            <span class="info-text">{{ user.userinfo.region || '未设置' }}</span>
          </el-form-item>

          <el-form-item label="学校">
            <span class="info-text">{{ user.userinfo.graduate || '未设置' }}</span>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "UserDetail",
  data() {
    return {
      user: this.$store.state.user
    }
  }
};
</script>

<style scoped>
.user-detail-container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.user-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.avatar-section {
  margin-bottom: 20px;
}

.avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #e0e0e0;
}

.no-avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background-color: #f0f0f0;
  color: #999;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  border: 2px solid #e0e0e0;
}

.info-section {
  width: 100%;
}

.info-text {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 4px;
  min-width: 100px;
}

.el-form-item__label {
  font-weight: bold;
}
</style>